﻿@using GitDC.Extensions
@using GitDC.Models
@using LibGit2Sharp
@model TreesModel
@{
    ViewBag.Title = Model.RepositoryName;

    string currRepo = (string)ViewContext.RouteData.Values["repoName"];
    string currUser = (string)ViewContext.RouteData.Values["userName"];
    string currId = (string)ViewContext.RouteData.Values["id"];
    var request = ViewContext.HttpContext.Request;
    var giturl = $"{request.Scheme}://{request.Host}/{currUser}/{currRepo}.git";
}
<div class="ui clearing segment">
    <h3 class="ui left floated header">@currUser / @currRepo</h3>
</div>
<h2>Contents of @Model.RepositoryName</h2>
<div class="ui fluid action input">
    <input type="text" value="@giturl" readonly>
    <button class="ui teal right labeled icon button"><i class="copy icon"></i> Copy </button>
</div>
@if (Model.IsRoot)
{
    <div class="ui segment" id="git-stats">
        <div class="ui two horizontal center link list">
            <div class="item">
                <a href="#"><span class="ui text black"><i class="icon history"></i> <b>@Model.Scope.Commits</b> 提交历史</span> </a>
            </div>
            <div class="item">
                <a href="#"><span class="ui text black"><i class="icon git"></i><b>@Model.Scope.Branches</b> 代码分支</span> </a>
            </div>
            <div class="item">
                <a href="#"><span class="ui text black"><i class="icon tag"></i> <b>@Model.Scope.Tags</b> 标签</span> </a>
            </div>
            <div class="item">
                <a href="#"><span class="ui text black"><i class="icon tag"></i> <b>@Model.Scope.Contributors</b> 参与</span> </a>
            </div>
        </div>
    </div>
}

<div class="ui top attached tabular menu">
    <a class="item active" data-tab="code">代码</a>
    <a class="item" data-tab="issues">Issues</a>
    <a class="item" data-tab="pull">Pull requests</a>
</div>
<table class="ui celled striped table">
    <thead>
        <tr>
            <th colspan="4">@Model.Commit.Author.Name &nbsp;&nbsp;<span class="ui label">@Model.Commit.CommitMessageShort</span>&nbsp;@Model.Commit.Author.When.LocalDateTime</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var entry in Model.Entries)
        {
            <tr>
                <td>
                    <span title="@entry.Name">
                        @if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.Tree)
                        {<span class="glyphicon glyphicon-folder-close"></span> }
                        else if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.Blob)
                        { <span class="glyphicon glyphicon-file"></span> }
                        else if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.GitLink)
                        { <i class="glyphicon glyphicon-bookmark"></i> }
                        else
                        { <span class="glyphicon glyphicon-leaf"></span>}
                        @if (entry.EntryType == LibGit2Sharp.TreeEntryTargetType.GitLink)
                        {
                            @entry.Name.ShortString(25)
                        }
                        else
                        {
                            <a href="@Url.UnencodedRouteLink((entry.EntryType.ToString() == "Tree") ? "GetTreeView" : "GetBlobView", new { repoName = currRepo, id = currId, path = @entry.Path })">@entry.Name.ShortString(25)</a>
                        }
                    </span>
                </td>
                <td><span title="@entry.Commit.CommitMessageShort">@(entry.Commit.Sha == null ? Html.Raw(entry.Commit.CommitMessageShort) : Html.ActionLink(entry.Commit.CommitMessageShort.ShortString(70), "Commit", Html.OverRoute(new { path = entry.Commit.Sha })))</span></td>
                <td title="@entry.Commit.Author">@entry.Commit.Author.Name.ShortString(20)</td>
                <td title="@entry.Commit.Author.When">@entry.Commit.Author.When.LocalDateTime.ToString()</td>
            </tr>
        }
    </tbody>
</table>
@if (Model.Readme != null)
{
    <div class="border-area">
        <table class="table">
            <caption>
                <div class="pull-left keep-space"><i class="glyphicon glyphicon-list-alt"></i> @Model.Readme.Name</div>
            </caption>
            <tbody>
                <tr>
                    <td>
                        @await Html.PartialAsync("_BlobPreview", Model.Readme)
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
}